package com.palm.hubo2o.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.palm.hubo2o.BaseFragment;
import com.palm.hubo2o.R;
import com.palm.hubo2o.model.QueryOrdersParams;

import butterknife.Bind;


/**
 * Created by wongqi on 16/6/14.
 */
public class OrderListFragment extends BaseFragment {
    @Bind(R.id.tab_order)
    TabLayout mTabLayout;
    @Bind(R.id.vp_order)
    ViewPager mViewPager;

    private final String[] types = {QueryOrdersParams.all, QueryOrdersParams.prize, QueryOrdersParams.waitprize};

    @Override
    protected int layoutId() {
        return R.layout.fragment_order_list;
    }

    @Override
    public void onCreateView2(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mViewPager.setAdapter(new OrderPagerAdapter(getChildFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
//        mViewPager.setEnabled(false);
    }


    private class OrderPagerAdapter extends FragmentPagerAdapter {

        public OrderPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return OrderChildFragment.getInstance(types[position]);
        }

        @Override
        public int getCount() {
            return types.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            String title = null;
            switch (position) {
                case 0:
                    title = "全部";
                    break;
                case 1:
                    title = "中奖";
                    break;
                case 2:
                    title = "待开";
                    break;
                default:
                    break;
            }
            return title;
        }
    }


}
